<template>
    <div class="contain">
        <!-- 异常类型标题 -->
        <div class="title">{{title}}</div>
        <div class="list">
        <el-row style="width=100%">
            <!-- 柱状图 -->
            <el-col :span="24" style="margin-bottom:20px;background:#fff;">
                <div id="chartColumn" style="width:100%; height:400px;"></div>
            </el-col>
            <!-- 曲线图 -->
            <el-col :span="24" style="margin-bottom:20px;background:#fff;">
                <div id="chartLine" style="width:100%; height:400px;"></div>
            </el-col>
            <!-- 饼图 -->
            <el-col :span="24" style="margin-bottom:20px;background:#fff;">
                <div id="chartPie" style="width:100%; height:400px;"></div>
            </el-col>
        </el-row>
        </div>
    </div>
</template>
<script>
import echarts from "echarts";
export default {
  data() {
    return {
      // 柱状图的数据
      chartColumn: null,
      // 曲线图的数据
      chartLine: null,
      // 饼图的数据
      chartPie: null,
      title: "综合分析"
    };
  },

  methods: {
    // 显示柱状图的方法
    drawColumnChart() {
      this.chartColumn = echarts.init(document.getElementById("chartColumn"));
      this.chartColumn.setOption({
        // 标题
        title: { text: "新增档案数" },
        tooltip: {},
        xAxis: {
          // 展示的数据
          data: [
            "2017年1~2月",
            "2017年3~4月",
            "2017年5~6月",
            "2017年7~8月",
            "2017年9~10月",
            "2017年11~12月"
          ]
        },
        yAxis: {},
        series: [
          {
            name: "借阅量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      });
    },
    // 显示曲线图的方法
    drawLineChart() {
      this.chartLine = echarts.init(document.getElementById("chartLine"));
      this.chartLine.setOption({
        tooltip: {
          trigger: "axis"
        },
        legend: {
          left: "10%",
          data: ["撤销", "借阅", "新增"]
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
        },
        yAxis: {
          type: "value"
        },
        series: [
          {
            name: "撤销",
            type: "line",
            stack: "总量",
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: "借阅",
            type: "line",
            stack: "总量",
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: "新增",
            type: "line",
            stack: "总量",
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      });
    },
    // 显示饼图的方法
    drawPieChart() {
      this.chartPie = echarts.init(document.getElementById("chartPie"));
      this.chartPie.setOption({
        title: {
          text: "档案来源",
          x: "center"
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: "vertical",
          left: "left",
          data: ["上市公司", "邮件营销", "联盟广告", "视频广告", "事业单位"]
        },
        series: [
          {
            name: "档案来源",
            type: "pie",
            radius: "55%",
            center: ["50%", "60%"],
            data: [
              { value: 335, name: "上市公司" },
              { value: 310, name: "邮件营销" },
              { value: 234, name: "联盟广告" },
              { value: 135, name: "视频广告" },
              { value: 1548, name: "事业单位" }
            ],
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            }
          }
        ]
      });
    },
    // 同时显示图形
    drawCharts() {
      this.drawColumnChart();
      this.drawLineChart();
      this.drawPieChart();
    }
  },

  mounted: function() {
    //调用方法，展示数据
    this.drawCharts();
  },
  updated: function() {
    //页面刷新，展示数据
    this.drawCharts();
  }
};
</script>

<style scoped>

</style>
